package com.tcode.controller;

import com.tcode.bean.UserBean;
import com.tcode.service.UserService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Random;

@RestController
@MapperScan("com.tcode.dao")
public class helloController {
    @Autowired
    private UserService us;
    @Autowired
    private RestTemplate rs;

    @GetMapping("helloSpringBoot")
    public List<UserBean> helloSpringBoot(){

        return us.getAllUser();
    }

    @GetMapping("findUser/{id}")
    public UserBean findUser(@PathVariable(name="id")int id){
        try{
            Thread.sleep(new Random().nextInt(2000));
        }catch(Exception e){

        }
        System.out.println("===========================port:9528");
        return us.getUserById(id);
    }
    @GetMapping("helloSpringt")
    public String helloSpringt(){
        List<UserBean> list = this.rs.getForObject("http://localhost:8080/springMVC/json/allUser", List.class);
        System.out.println(list.toString());
        return list.toString();
    }
}
